<?php
/**
 * 教练预约管理
 * @author Administrator
 */
class yuyue extends admin{
    public function __construct(){
        parent::__construct();
    }
    
    //教练预约列表
    public function index(){  
       $where='1=1';
       if(isset($_GET['k'])&&$_GET['k']!='') {
           $k=trim($_GET['k']);
           if(preg_match('/^1[3-9][0-9]{9}$/',$k)) $where.=' and u.mobile='.$k;
           else $where.=' and u.real_name like "%'.$k.'%"';
       }
       if(isset($_GET['book_date'])&&$_GET['book_date']!='') $where.=' and cb.book_date="'.trim($_GET['book_date']).'"';
       if(isset($_GET['book_kemu'])&&(int)$_GET['book_kemu']>0) $where.=' and cb.book_kemu="'.(int)$_GET['book_kemu'].'"';
       if(isset($_GET['status'])&&is_numeric($_GET['status'])) $where.=' and cb.status='.(int)$_GET['status'];
       $count=db()->getOne('select count(*) from x_coach_book as cb left join x_user as u on u.id=cb.uid where '.$where);
       $pagesize=C('PAGE_SIZE');
       if(isset($_GET['page'])&&(int)$_GET['page']>0) $p=(int)$_GET['page'];
       else $p=1;
       $max_p = ceil($count/$pagesize);
       if($p>=$max_p) $p = $max_p;
       $limit=' limit '.($p-1)*$pagesize.','.$pagesize;
       $list=db()->getAll('select cb.*,u.mobile,u.real_name from x_coach_book as cb left join x_user as u on u.id=cb.uid where '.$where.' order by cb.id DESC'.$limit);
       //var_dump($list);
       //exit;
       $tpl=$this->Template();
       $tpl->assign('list',$list);
       $page=pages($pagesize,$count);
       $tpl->assign('page',$page);
       $tpl->display(); 
    }
    
    //编辑用户
    public function edit(){
        if(IS_AJAX){
    
        }else{
            $id=(int)$_GET['id'];
            $vo=db()->getRow('select * from x_yuyue where id='.$id);
            $tpl=$this->Template();
            $tpl->assign('vo',$vo);
            $tpl->display();
        }
    }
}